package com.company.card_service.api;

import com.company.card_service.service.EmployeeViewService;
import com.company.card_service.vo.EmployeeAllUsers;
import com.company.card_service.vo.Result;
import com.company.card_service.vo.ResultCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api("小程序端客户管理")
@RestController
@RequestMapping("api/company/user")
public class ApiUserController {

    @Autowired
    private EmployeeViewService employeeViewService;

    @ApiOperation("客户管理-客户概况-近7日客户趋势")
    @GetMapping("getUserDay/{employeeId}")
    public Result getUserDay(
            @ApiParam(name = "employeeId", value = "员工的id", required = true)
            @PathVariable Integer employeeId){
        Map<String,Object> map =  employeeViewService.getUserDay(employeeId);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),map);
    }

    @ApiOperation("客户管理-全部用户")
    @GetMapping("selectAllUsers/{employeeId}/{page}/{limit}")
    public Result selectAllUsers(
            @ApiParam(name = "employeeId", value = "员工的id", required = true)
            @PathVariable Integer employeeId,
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit){
        List<EmployeeAllUsers> employeeAllUsers = employeeViewService.selectAllUsers(employeeId,page,limit);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),employeeAllUsers);
    }

    @ApiOperation("客户管理-查找客户")
    @GetMapping("queryAllUsersByPhone/{employeeId}/{phone}/{page}/{limit}")
    public Result queryAllUsersByPhone(
            @ApiParam(name = "phone", value = "用户电话", required = true)
            @PathVariable String phone,
            @ApiParam(name = "employeeId", value = "员工的id", required = true)
            @PathVariable Integer employeeId,
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit){
        List<EmployeeAllUsers> employeeAllUsers =  employeeViewService.queryAllUsersByPhone(employeeId,phone,page,limit);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),employeeAllUsers);
    }
}
